def calc_avg_value():
    total, count, avg = 0, 0, None
    while True:
        # 1. 产出 - 平均值
        # 2. 让步 - 让出CPU给协作的子程序
        current_value = yield avg
        total += current_value
        count += 1
        avg = total / count


def main():
    gen = calc_avg_value()
    # 对生成器对象进行预激活，使其变成一个协程对象
    gen.send(None)
    print(gen.send(10))
    print(gen.send(20))
    print(gen.send(30))
    print(gen.send(40))


if __name__ == '__main__':
    main()
